package com.lggry.array;

public class ArrayDemo3 {
    public static void main(String[] args) {
        //1.目标：完成数组求最值
//        int[] score = {15,9000,10000,20000,9500,-15};
//        getMaxAndMin(score);
        //2.完成斗地主游戏的做牌和洗牌
        poker();

    }
    public static void getMaxAndMin(int[] arr){
        int max = arr[0];
        int min = arr[0];
        for(int i=0;i<arr.length;i++){
            if(arr[i]>max){
                max = arr[i];
            }
            if(arr[i]<min){
                min = arr[i];
            }
        }
        System.out.println("最大值是：" + max);
        System.out.println("最小值是：" + min);
    }
    public static void poker(){
        //1.准备牌,创建一个动态初始化的数组组成54张牌
        String[] poker = new String[54];
        //2.准备四种花色，还有点数，再开始做牌存入数组中
        String[] colors = {"♦","♣","♥","♠"};
        String[] numbers = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};

        int index = 0;
        //3.遍历点数，再遍历花色
        for(int i = 0;i<numbers.length;i++){
            for (int j = 0;j<colors.length;j++){
                poker[index++] = colors[j] + numbers[i];
            }
        }
        poker[index++] = "Joker";
        poker[index] = "joker";

        //4.打印牌
        for(int i = 0;i<poker.length;i++){
            System.out.print(poker[i] + " ");
        }
        System.out.println("\n");
        //5.洗牌，把54张牌的数组poker中的顺序打乱
        for(int i = 0;i<poker.length;i++){
            int index1 = (int)(Math.random()*poker.length);
            int index2 = (int)(Math.random()*poker.length);
            String temp = poker[index1];
            poker[index1] = poker[index2];
            poker[index2] = temp;
        }
        System.out.println("洗牌后：");
        for(int i = 0;i<poker.length;i++){
            System.out.print(poker[i] + " ");
        }
    }
}
